# -*- coding: utf-8 -*-
from django.db import models
from vdir.models import VDir

# 虚拟文件
class VFile(models.Model):
	#文件名
    name = models.CharField(max_length=64)
    #对应的目录
    dir = models.ForeignKey(VDir)
    #checksum
    checksum = models.CharField(max_length=64)
    ver = models.IntegerField(default=0)
    create_date = models.DateTimeField(auto_now_add = True)
    update_date = models.DateTimeField(auto_now_add = True)

    def get_full_path(self):
        return self.dir.get_full_path()+self.name


    def add_ver(self):
        self.ver=self.ver+1


    def get_url(self):
        return '/site_media'+self.get_full_path()

    def update(self):
        self.update_date=datetime.datetime.now()